function show_table(a){$("#tbody").html("");$(cart_data).each(function(){var f=(a?parseFloat(this.price[a]):this.sel),e=$('<tr id="'+this.id+'" class="'+(this.sel?"lightyellow_bg":"")+'"></tr>').append($('<td><input id="c'+this.id+'" class="cbx" type="checkbox" value=""'+(f?'checked=""':"")+'/></td><td class="book_title"><a target="blank" href="'+this.path+'">'+this.title+"</a></td><td><strike>"+this.oprice+"</strike></td>"));var b=99999;for(var c=0;c<vids.length;c++){var d=parseFloat(this.price[vids[c]]);if(d<b){b=d}}for(var c=0;c<vids.length;c++){if(parseFloat(this.price[vids[c]])==b){e.append($('<td class="color-orange">'+this.price[vids[c]]+"</td>"))}else{if(this.price[vids[c]]=="-"){e.append($('<td class="color-gray">'+this.price[vids[c]]+"</td>"))}else{e.append($("<td>"+this.price[vids[c]]+"</td>"))}}}
e.append($('<!-- <td><input name="" class="w20" disabled=1 id="n'+this.id+'"value="'+this.num+'"/></td> --> <td >&gt; <a href="javascript:;" class="delete_item" id="d'+this.id+'" rel="'+this.sid+'">删除</a></td>'));$("#tbody").append(e)});$(".cbx").click(update_data);$(".w20").keyup(update_data);
$(".delete_item").click(function(){
	var b=this;
	$.post_withck(	"cart",
					{remove:b.rel},
					function(){
						cart_data=$.grep(	cart_data,
											function(c){
												return"d"+c.id!=b.id
											}
										);
						$(b).parent().parent().fadeOut();
						if(!cart_data.length){
							location.href="/mine/my_tianya_post"
						}
						update_data()
					}
				)
			}
		);
if(a){update_data()}}function sort_table(a){update_data();cart_data.sort(function(d,c){return(parseFloat(d.price[a])||1000)-(parseFloat(c.price[a])||1000)});show_table()}
function update_data()
{	
	$(cart_data).each(
	function(){
		var h=this.id;
		this.sel=$("#c"+h)[0].checked;
		this.num=parseInt($("#n"+h).val())||0;
		if(this.num<0){
			this.num=0
		}
		$("#"+h)[0].className=this.sel?"lightyellow_bg":""
	}
);
var g=$.grep(cart_data,function(h){return h.sel});for(var c in vnames){var e=$(g).chop(function(h){return parseFloat(h.price[c])}),f=$.map(e[0],function(h){return{num:h.num,price:h.num*parseFloat(h.price[c])}}),d=$(g).sum("num"),a=$(f).sum("num"),b=$(f).sum("price");$(".sum_"+c).text(b?b.toFixed(2):"");$(".books_len_"+c).text(a?a+"本"+vnames[c]+"总价:":"");$(".total_down_"+c).text(a?a+"本":"")}$("#total_down").text(d?"选中"+d+"本":"");$("#total_count").text(d);return $.map(g,function(h){return h.sid})}$(function(){$(".choose_vendor").click(function(){sort_table(this.rel);show_table(this.rel);$(".sort_price").removeClass("on");$(".choose_vendor").removeClass("on");$("#sort_price_"+this.rel).addClass("on");$.get("/stat.html?ref=/book/cart&vendor=v"+this.rel)});$("#select_all").click(function(){$(".cbx").each(function(){this.checked=true});update_data()});$("#select_none").click(function(){$(".cbx").each(function(){this.checked=false});update_data()});$("#clear_cart").click(function(){sids=$.map($.grep(cart_data,function(a){return a.sel}),function(a){return a.sid});if(confirm("确定要删除选中图书？")){$.post_withck("cart",{clear:sids.join("_")},function(){location.href="/mine/my_tianya_post"})}});$(".submit_cart").click(function(){var a=this.name,b=update_data();sids=$.map($.grep(cart_data,function(c){return c.sel&&parseFloat(c.price[a])}),function(c){return c.sid});if(!sids.length){alert("没有选中图书，或者选中的图书在"+vnames[a]+"全部缺货");return false}window.open("?submit=1&vendor="+a+"&sids="+sids.join("_"));pop_win($("#clear_dialog").html());$(".sel_ids").val(b.join("_"));$(".n_sel").text(b.length)});show_table();update_data()});